<div class="container-fluid" style="padding: 20px 10px 0px 10px">

    <div class="row-fluid">

        <div class="well">

            <div id="myTabContent" class="tab-content">

                <div class="tab-pane active in" id="home">

                    <form id="formid" action="/take/takeMaterialAdd" method="post">
                        <input type="hidden" name="id" value="<?=$takeData['id']?>">

                        <ul class="nav nav-tabs">

                            <li class="active"><b>耗材列表</b></li>
                            <div>
                                <a href="javascript:;" id="del_drug" style="float:right;padding:3px 6px; margin-left: 10px;">-删除</a>
                                <?php if($takeData){?>
                                <button class="btn btn-primary ifrm" data-url="/take/take_material" data-width="720" data-height="420" data-title="添加耗材" data-params="take_id/<?=$takeData['id']?>/orderid/<?=$takeData['order_id']?>" style="float:right;padding:3px 6px">添加耗材</button>
                                <?php }?>
                            </div>
                        </ul>
                        <table style="border: 0; width: 100%" id="drug_box">
                            <tr>
                                <td><input type="checkbox" name="all"></td>
                                <td>序号</td>
                                <td>药品编号</td>
                                <td>名称</td>
                                <td>所属仓库</td>
                                <td>规格类型</td>
                                <td>单位</td>
                                <td>领出量</td>
                                <td>备注</td>
                                <td>操作</td>
                            </tr>
                            <?php if($drugList){ foreach($drugList as $val){ ?>
                            <tr style="height:37px; width: 100%">
                                <td><input type="checkbox" name="did" value="<?=$val['id']?>"></td>
                                <td><?=$val['id']?></td>
                                <td><?=$val['drugMsg']['drug_no']?></td>
                                <td><?=$val['drugMsg']['drug_name']?></td>
                                <td><?=storageName($val['warehouse'])?></td>
                                <td><?=$val['drugMsg']['drug_size']?></td>
                                <td><?=$val['drugMsg']['drug_unit']?></td>
                                <td><?=$val['take_num']?></td>
                                <td style="width: 15%" title="<?=$val['remark']?>"><?=cut_str($val['remark'],16) ?: '-'?></td>
                                <td>
                                    <button class="ifrm btn btn-primary" data-url="/take/take_material" data-width="720" data-height="420" data-title="修改耗材信息" data-params="take_id/<?=$takeData['id']?>/id/<?=$val['id']?>/orderid/<?=$takeData['order_id']?>" style=" padding: 0 6px;">修改</button>
                                </td>
                            </tr>
                            <?php }}else{?>
                            <tr>
                                <td colspan="13" style="text-align: center; height: 30px;">暂无数据</td>
                            </tr>
                            <?php }?>
                        </table>
                        <hr>
                        <p>
                            <label style="display:inline-block; width: 70px; text-align: right">领用地点 : </label>

                            <input type="text" name="take_place" style="width: 100px;" value="<?=$takeData['take_place']?>">
                            <label style="display:inline;margin-left: 100px;">领用日期 : </label>

                            <input readonly name="take_date" placeholder="领用日期" class="input input-medium"
                                   onclick='WdatePicker({dateFmt:"yyyy-MM-dd"})' type="text" value="<?=$takeData['take_date']?>"/>

                            <label style="display:inline;margin-left: 119px;">发货人 : </label>

                            <input type="text" name="send_user" style="width: 100px;" value="<?=$takeData['send_user']?>" class="">

                        </p>

                        <p style="width: 100%">
                            <label style="display:inline-block; width: 70px; text-align: right">领取人 : </label>

                            <input type="text" name="take_users" style="width: 729px;" value="<?=$takeData['take_users']?>" class="">
                        </p>
                        <p>
                            <label style="display:inline-block; width: 70px; text-align: right">备注 : </label>
                            <textarea style="display:inline;width: 729px; height: 83px;" name="remark"><?=$takeData['remark']?></textarea>
                        </p>
                        <input type="hidden" name="dosubmit" value="1">
                        <div class="btn-toolbar">
                            <div class="btn-group" style="margin:30px 0 10px 350px;">
                                <input type="submit" name="" value="保存" id="btn-save" class="btn btn-primary">
                            </div>
                        </div>
                    </form>

                </div>

            </div>

        </div>

    </div>

    <script>

        $(function(){

            $('#btn-save').click(function(){
                $('#formid').submit();
            });

            checked_unchecked_all();
            function checked_unchecked_all() {
                var checked_all_btn = $('#drug_box').find('input[name="all"]');//获取全选按钮
                var checked_item = $('#drug_box').find('input[name="did"]');//获取单选按钮

                checked_all_btn.on('click',function () {
                    if($(this).attr('checked')){
                        checked_item.attr('checked',true);
                    }else {
                        checked_item.attr('checked',false);
                    }
                });

            }
            checked_unchecked_all_out();
            function checked_unchecked_all_out() {
                var checked_all_btn = $('#drug_box_out').find('input[name="all_out"]');//获取全选按钮
                var checked_item = $('#drug_box_out').find('input[name="did_out"]');//获取单选按钮

                checked_all_btn.on('click',function () {
                    if($(this).attr('checked')){
                        checked_item.attr('checked',true);
                    }else {
                        checked_item.attr('checked',false);
                    }
                });

            }

            //删除
            $('#del_drug').click(function () {
                checked_delete();
            });

            function checked_delete() {
                var checked_all_btn = $('#drug_box').find('input[name="all"]');//获取全选按钮
                var checked_item = $('#drug_box').find('input[name="did"]');//获取单选按钮

                var check_box_val = '';
                checked_item.each(function (index,item) {
                    if($(item).attr('checked')){
                        var val = $(item).attr('value');
                        check_box_val += (val+',');
//                        check_box_val.push(val);
                    }
                });

                $.ajax({
                    url: '/take/del_takeMaterial',
                    type: 'POST',
                    dataType: 'json',
                    data: {ids: check_box_val},
                })
                    .done(function(data) {
                        if(data.code){
                            alert(data.msg);
                            location.reload();
                        }
                    })
                    .fail(function() {
                        console.log("error");
                    })
            }



        })

    </script>